package demo1;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-10-08
 * Time: 19:40
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if(n == 1 || n == 0){
            System.out.println(0);
            return;
        }
        int a = 0, b = 1, c = 0;
        while(c < n){
            c = a + b;
            if(c >= n){
                break;
            }
            a = b;
            b = c;
        }
        if(c == n){
            System.out.println(0);
            return;
        }
        int len1 = n - b;
        int len2 = c - n;
        if(len1 < len2){
            System.out.println(len1);
        }else{
            System.out.println(len2);
        }
    }
}
